package Figures;

import Tools.PropertyManager;

import java.awt.*;

import java.awt.geom.Rectangle2D;
import java.io.Serializable;

/**
 * 类功能描述：矩形类，实现了绘制,填充,移动矩形等方法
 *
 * @author lix
 * @date 2023/12/28
 */

public class MyRectangle extends ClosedGraphics  implements Serializable {


    private Rectangle2D rectangle2D;


    /**
     * 功能描述：
     *初始化矩形对象
     * @param start 起点
     * @param end   终点
     * @author lix
     * @date 2023/12/29
     */

    public MyRectangle(Point start,Point end,int size,Color color) {
        super(start,end,size,color);
        rectangle2D = new Rectangle2D.Double(point_left_top.x,point_left_top.y,width,height);

    }

    @Override
    public void fill(Graphics2D g) {
        g.setColor(getFillColor());
        g.fill(rectangle2D);
    }

    @Override
    public void Draw(Graphics2D g) {
        g.setColor(ShapeColor);
        g.setStroke(new BasicStroke(size));
        g.draw(rectangle2D);
        if(fillColor != null){
            g.setColor(fillColor);
            g.fill(rectangle2D);
        }
        if(isSelected) showSelectBorder(g);
    }




    @Override
    public void setEnd(Point end) {
        super.setEnd(end);
        //计算左上角和右下角和高度
        calcPoint_left_top();
        calcPoint_right_bottom();
        calcWidthAndHeight();
        rectangle2D.setRect(point_left_top.x,point_left_top.y,width,height);
        point_center = new Point(((point_left_top.x+point_right_bottom.x)/2),(point_left_top.y+point_right_bottom.y)/2);
    }

    @Override
    public void Move(Point destination) {
        super.Move(destination);
        rectangle2D.setRect(point_left_top.x,point_left_top.y,width,height);
    }
}
